// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from 'axios'
Vue.use(ElementUI);


//设置axios对象
axios.defaults.baseURL = "http://localhost:8888/"
Vue.prototype.$http = axios;
axios.defaults.withCredentials = true

axios.interceptors.response.use(function(resp) {
	if(resp.data.code == 403) {
		localStorage.removeItem("loginAccount");
		router.push("/");
	} else return resp;
})
//路由前置守卫判断是否登陆
router.beforeEach((to,from,next) => {
	if(to.path == "/") {
		next();return;
	}
	let account = localStorage.getItem("loginAccount");
	if(account == undefined) {
		router.push("/");
	} else next();
})
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
